package com.zret.oasys.operation.leave;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.zret.oasys.dbtools.PageData;
import com.zret.oasys.entity.Leavetable;
import com.zret.oasys.json.entity.GetTableDataJson;
import com.zret.oasys.json.entity.MsgJson;

public class LeaveMsgList implements LeaveServletOperation {

	@Override
	public void doOperation(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 设置编码格式
		request.setCharacterEncoding("utf-8");
		response.setContentType("application/json;charset=utf-8");
		// 输出流对象
		PrintWriter out = response.getWriter();
		// JSON传输对象及格式化对象
		Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
		MsgJson msg = new MsgJson();
		// 需要向叶面获取的参数
		int empid = 0;
		if(request.getParameter("empid") != null) {
			empid = Integer.valueOf(request.getParameter("empid"));
		}
		// 获取选择框选择的栏目(已审批, 未审批, 所有)
		String searchtype = "all";
		if(request.getParameter("searchType") != null) {
			searchtype = request.getParameter("searchType");
		}
		System.out.println(searchtype);
		// 获取当前页与每页限制
		int page = Integer.valueOf(request.getParameter("page"));
		int pageSize = Integer.valueOf(request.getParameter("limit"));
		// 向service获取请求数据列表
		PageData<Leavetable> pd = leaveService.getMyselfLeaveMsg(empid, searchtype, page, pageSize);
		System.out.println(pd.getData());
		
		GetTableDataJson<Leavetable> table = new GetTableDataJson(0, "", pd.getTotalCount(), pd.getData());
		String jsonObj = gson.toJson(table);
		System.out.println(jsonObj);
		out.print(jsonObj);
		out.close();
	}

}
